function main() {

  //  com.youzu.shaoxiagame.aligames
    var libnative_addr = Module.findBaseAddress("libil2cpp.so")
    console.log("libnative_addr is: " + libnative_addr)

    // var luaL_loadbufferx_addr = Module.findExportByName("libcocos2dlua.so",  "luaL_loadbuffer")
    var luaL_loadbufferx_addr = libnative_addr.add(0x01AC9A00)
    var luaL_loadbufferx_name = libnative_addr.add(0x01AC9AA4)
    // var lua_pcall_addr = Module.findExportByName("libcocos2dlua.so",  "lua_pcall")
 
    console.log("luaL_loadbufferx is: " + luaL_loadbufferx_addr)
  
  
    var tmp = 0
    var byteArray = null
    Interceptor.attach(luaL_loadbufferx_addr, {
        onEnter: function(args) {
            var name = Memory.readCString(args[3])
            // console.log("--->111"+args[1])
            var data = ptr(args[1]).add(16)
            var datalen = args[2].toInt32()
            byteArray = Memory.readCString(data)
           // console.log(byteArray)
            if(name.indexOf("@")!=-1 || true){
               // console.log("--->"+args[0])
                name = name.replaceAll("/",".")
                tmp++
                var file = new File('/sdcard/zzzz/test'+tmp+ '.lua', 'w')
                // file.write(data.readByteArray(datalen))
                file.write(byteArray)
                file.flush();
                file.close();
                console.log("--->"+name)
            }
           
        },
        onLeave: function(ret) {
          return ret
        }
    })
 
    if(false)
    Interceptor.attach(luaL_loadbufferx_name, {
      onEnter: function(args) {
          // var name = Memory.readCString(args[3])
          // console.log("--->"+name)
          // console.log(this.context.r4)
          // console.log(Process.findModuleByAddress(this.context.r4).name)
          
      },
      onLeave: function(ret) {
         return ret
      }
  })

}

 
let sleep = function(fun,time){
  setTimeout(()=>{
    main();
  },time);
}

sleep(main,10000);
// setImmediate(main)



function test() {
    var luaL_loadbufferx_addr = Module.findExportByName("libtolua.so",  "luaL_loadbufferx")
    var lua_pcall_addr = Module.findExportByName("libslua.so",  "lua_pcall")

    var luaL_loadbufferx = new NativeFunction(luaL_loadbufferx_addr , "int", ["pointer", "pointer" , "int", "pointer"])
    var lua_pcall = new NativeFunction(lua_pcall_addr , "int", ["pointer","int","int","int"])
    if( true){
 
         var luastr = "local CombatView = require \"mod/combat/combat_view\"\n"
         +"print(CombatView)\n"
         +"CombatView.CheckCanSkip = function(self, ...)\n"
         +"\tlocal msg = \"skip11111\"\n"
         +"\treturn true,msg\n"
         +"end\n"
         +" \n"
         +"CombatView.CheckShowSkipBtn = function(self, ...)\n"
         +"\treturn true\n"
         +"end"
         console.log(luastr)
         var strName = "hello.lua"
  
         var lua = Memory.allocUtf8String(luastr)
         var size = luastr.length
         var luaName = Memory.allocUtf8String(strName);



         var lua_State = 0xe0ac31c0

         console.log(ptr(lua_State))
         console.log(lua)
         console.log(size)
         console.log(luaName)
     
         luaL_loadbufferx(ptr(lua_State),(lua),size,(luaName))
         lua_pcall(ptr(lua_State),0,0,0)
         console.log("注入lua hook")
    }
}


//frida -U rongyaozg.aligames -l ryzg.js
//frida -U com.kaiqigu.dancer.uc -l ryzg.js
//frida -U com.cmge.xyjjzy.uc -l ryzg.js
//frida -U com.fcjflsdk.yx7477 -l ryzg.js
//frida -U com.youzu.shaoxiagame.aligames -l c2ddumplua.js
//frida -U com.xy51.sn -l c2ddumplua.js
//frida -U com.xy.msyxz.aligames -l c2ddumplua.js
// frida -U com.xy.msyxz.aligames -l il2cpplua.js
//frida -U --no-pause -f com.xy.msyxz.aligames -l

